// Read the Phantom webpage '.version' element text using jQuery and "includeJs"

"use strict";
var page = require('webpage').create();

//page.onConsoleMessage = function(msg) {
//  console.log(msg);
//};
//
//page.open("http://www.pcsoft.com.cn", function(status) {
//  if (status === "success") {
//      page.includeJs("http://www.pcsoft.com.cn/statics/js/jquery-1.8.3.min.js", function() {
//      	console.log(page.evaluate(function() {
//      		var d = $(".head").html();
//      		return d;
//      		
//      	}))
////          page.evaluate(function() {
////              // lastest version on the web
//////              console.log("$(\"div.head\").html()-> " + $("div.head").html());
////          });
//          phantom.exit(0);
//      });
//  } else {
//    phantom.exit(1);
//  }
//});


page.open('http://www.pcsoft.com.cn',function(status) {
	if(status !== "success") {
		console.log("fail to open");
	}else {
		console.log(page.evaluate(function() {
			var d = "";
			var c = document.querySelectorAll('body');
			for(var i = 0; i < c.length; i++) {
				d = d + c[i].innerHTML;
				return d;
			}
		}))
	}
	phantom.exit();
})
